<template>
  <div>
    <input type="text" v-model="username" />
  </div>
  <div>
    <input type="text" v-model="password" />
  </div>
  <div>
    <button @click="login">登录</button>
  </div>
</template>

<script lang='ts' setup>
import { ref } from "vue";
import { useRouter } from "vue-router";
const router = useRouter();
const user = ref([
  { _id: 1, name: "张三", age: 18 },
  { _id: 2, name: "李四", age: 19 },
  { _id: 3, name: "刘灿", age: 20 },
  { _id: 4, name: "武若冰", age: 21 },
]);

const username = ref("");
const password = ref("");
const login = () => {
  user.value.forEach((item) => {
    if(item.name === username.value){
        router.push({
            name:"chat",
            query:{username:item.name}
           
        })
        localStorage.setItem("user",JSON.stringify(item))
        localStorage.setItem("avatar","/img/aaa.png")
    }
  })
};
</script>

<style lang="scss">
</style>
